package com.adnaan.restaurant.mapper;

import com.adnaan.restaurant.entity.ResCollect;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ResCollectMapper {
    @Select("<script>" +
            "select c.id,c.user_id,c.shop_id,c.create_time,s.name,s.cover,s.address from res_collect c " +
            "left join res_shop s on s.id=c.shop_id " +
            "where c.user_id=#{userId} " +
            "<if test='shopId!=null'>" +
            "and c.shop_id=#{shopId}" +
            "</if>" +
            "</script>")
    List<ResCollect> selectResCollectList(ResCollect resCollect);

    @Insert("insert into res_collect(shop_id, user_id, create_time) VALUES (#{shopId},#{userId},now())")
    int addCollect(ResCollect resCollect);

    @Delete("delete from res_collect where shop_id=#{shopId} and user_id=#{userId}")
    int cancelCollect(ResCollect resCollect);
}
